<template>


  <div>

    <!--  查询-->
    <el-card>

      <el-form inline label-width="90px" size="mini" class="demo-form-inline">

        <el-form-item label="姓名">
          <el-input placeholder="请输入姓名" v-model.trim="queryParam.name" clearable size="mini"></el-input>
        </el-form-item>
        <el-form-item label="性别">
          <el-input placeholder="请输入性别" v-model.trim="queryParam.sex" clearable size="mini"></el-input>
        </el-form-item>
        <el-form-item label="角色/职位">
          <el-input placeholder="请输入组织角色/职位" v-model.trim="queryParam.orgRole" clearable size="mini"></el-input>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input placeholder="请输入手机号" v-model.trim="queryParam.phone" clearable size="mini"></el-input>
        </el-form-item>
        <el-form-item label="正向/负向">
          <el-select v-model="queryParam.influenceTrend" placeholder="请选择" clearable  >
            <el-option key="1" label="正向" :value="1"/>
            <el-option key="0" label="负向" :value="0"/>
          </el-select>
        </el-form-item>
        <el-form-item label="沟通负责人">
          <el-input placeholder="请输入沟通负责人" v-model.trim="queryParam.interactPerson" clearable size="mini"></el-input>
        </el-form-item>



        <el-form-item>
          <el-button type="success" size="mini" @click="getListPage">查询</el-button>
          <el-button type="info" size="mini" @click="resetQuery">重置</el-button>
          <el-button type="warning" size="mini" @click="openSaveBefore">新增</el-button>
        </el-form-item>

      </el-form>

    </el-card>





    <!--列表-->
    <el-card style="margin-top: 10px">

      <el-table
          :data="tableData"
          max-height="650px"
          height="650px"
          style="width: 100%">


        <el-table-column prop="name" label="姓名"/>
        <el-table-column prop="sex" label="性别">
          <template slot-scope="scope">
            <el-tag  size="mini" v-if="scope.row.sex === 1">男性</el-tag>
            <el-tag type="success" size="mini" v-else-if="scope.row.sex === 0">女性</el-tag>
            <el-tag type="info" size="mini" v-else-if="scope.row.sex === 9">未知</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="phone" label="手机号"/>
        <el-table-column prop="rightLevel" label="权利级别">
          <template slot-scope="scope">
            <el-tag type="danger" size="mini" v-if="scope.row.rightLevel === 'high'">高</el-tag>
            <el-tag type="success" size="mini" v-else-if="scope.row.rightLevel === 'middle'">中</el-tag>
            <el-tag type="info" size="mini" v-else-if="scope.row.rightLevel === 'low'">低</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="levelCh" label="组织层级"/>
        <el-table-column prop="influenceTrend" label="正向/负向影响">
          <template slot-scope="scope">
            <el-tag type="warning" size="mini" v-if="scope.row.influenceTrend === 1">正向</el-tag>
            <el-tag type="info" size="mini" v-else-if="scope.row.influenceTrend === 0">负向</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="projectRoleCh" label="项目内角色"/>
        <el-table-column prop="interestLevel" label="利益级别">
          <template slot-scope="scope">
            <el-tag type="danger" size="mini" v-if="scope.row.interestLevel === 'high'">高</el-tag>
            <el-tag type="success" size="mini" v-else-if="scope.row.interestLevel === 'middle'">中</el-tag>
            <el-tag type="info" size="mini" v-else-if="scope.row.interestLevel === 'low'">低</el-tag>
          </template>
        </el-table-column>



        <el-table-column label="操作" width="200">
          <template slot-scope="scope">
            <el-button @click="openViewBefore(scope.row)" type="text" size="small"><i class="el-icon-view"></i>查看</el-button>
            <el-button @click="openUpdBefore(scope.row)" type="text" size="small"><i class="el-icon-edit"></i>编辑</el-button>
            <el-button @click="delTips(scope.row)" type="text" size="small"><i class="el-icon-delete"></i>删除</el-button>
          </template>
        </el-table-column>

      </el-table>


      <!--分页部分-->
      <el-pagination
          style="width:33%; margin-right:10px; margin-top:10px;"
          background
          layout="total, prev, pager, next, jumper"
          @current-change="pageCurrentChange"
          :page-size="pageConfig.size"
          :current-page="pageConfig.current"
          :pager-count="5"
          :total="pageConfig.total">
      </el-pagination>

    </el-card>

    <OpsStakeholderSaveUpd  ref="OpsStakeholderSaveUpdRef" @getListPage="getListPage"/>
    <OpsStakeholderDetailed ref="OpsStakeholderDetailedRef"/>

  </div>

</template>


<script>

import http from '@/utils/http'
import OpsStakeholderSaveUpd  from './OpsStakeholderSaveUpd.vue'
import OpsStakeholderDetailed from './OpsStakeholderDetailed.vue'


export default {
  name: "OpsStakeholderList",
  components: {
    OpsStakeholderSaveUpd,
    OpsStakeholderDetailed,
  },
  data() {
    return {
      // 查询参数
      queryParam: {
        id: null,
        siteId: null,
        ico: null,
        name: null,
        sex: null,
        age: null,
        level: null,
        stakeholderType: null,
        orgRole: null,
        projectRole: null,
        email: null,
        phone: null,
        benefitPoint: null,
        benefitClass: null,
        influenceTrend: null,
        influenceField: null,
        rightLevel: null,
        interestLevel: null,
        interestQuadrant: null,
        supportId: null,
        interactTarget: null,
        interactFrequency: null,
        interactFormat: null,
        interactPerson: null,
        dependentOneself: null,
        dependentProject: null,
        decisionStyle: null,
        motivation: null,
        taboo: null,
        education: null,
        updateTime: null,
        updateId: null,
        createTime: null,
        createId: null,
        delType: null,
      },
      // 分页参数
      pageConfig: {
        // 每页记录数
        size: 20,
        // 当前页码
        current: 1,
        // 总记录数
        total: 0,
      },
      // 表格数据
      tableData: [],
    }
  },
  methods: {
    /**
     * 打开保存的弹框
     */
    openSaveBefore() {
      this.$refs.OpsStakeholderSaveUpdRef.init('save', null)
    },
    /**
     * 查看之前触发
     * @param obj 这一行数据
     */
    openViewBefore(obj){
      this.$refs.OpsStakeholderDetailedRef.init(obj)
    },
    /**
     * 打开修改之前的的弹出框
     * @param obj 修改的值
     */
    openUpdBefore(obj) {
      this.$refs.OpsStakeholderSaveUpdRef.init('upd', obj)
    },
    /**
     * 删除之前的提示框
     * @param obj 要删除的数据
     */
    delTips(obj) {
      this.$confirm('是否执行删除, 删除后无法恢复，是否继续?', '提示', {
        confirmButtonText: '确定删除',
        cancelButtonText: '取消删除',
        type: 'warning'
      }).then(() => {
        // 确定删除
        this.delOpsStakeholder(obj)

      }).catch(() => {
        // 取消删除
      });
    },
    /**
     * 删除
     * @param obj 要删除的数据
     */
    delOpsStakeholder(obj) {
      http.post("opsStakeholder/delOpsStakeholder", {
        id: obj.id,
      }).then(response => {
        let res = response.data;
        this.getListPage()
        this.$message.success("删除成功");

      }).catch(error => {
        this.$message.error (error.message)
      })
    },
    /**
     * 分支分页查询列表
     */
    getListPage() {
      this.queryParam.current = this.pageConfig.current
      this.queryParam.size = this.pageConfig.size
      this.queryParam.siteId = this.$route.query.siteId
      http.post("/opsStakeholder/getListPage", this.queryParam).then(response => {
        let res = response.data;
        // 分页数据
        let data = res.data;
        this.pageConfig.total = data.total;
        this.pageConfig.current = data.current;
        this.pageConfig.size = data.size;
        // 表格数据
        this.tableData = data.records

      }).catch(error => {
        this.$message.error (error.message);
      })
    },
    /**
     * 分页被改变的时候
     * @param value 当前页
     */
    pageCurrentChange(value) {
      this.pageConfig.current = value
      this.getListPage()
    },
     /**
     * 重置查询条件
     */
    resetQuery() {
      this.queryParam = {
        id: null,
        siteId: null,
        ico: null,
        name: null,
        sex: null,
        age: null,
        level: null,
        stakeholderType: null,
        orgRole: null,
        projectRole: null,
        email: null,
        phone: null,
        benefitPoint: null,
        benefitClass: null,
        influenceTrend: null,
        influenceField: null,
        rightLevel: null,
        interestLevel: null,
        interestQuadrant: null,
        supportId: null,
        interactTarget: null,
        interactFrequency: null,
        interactFormat: null,
        interactPerson: null,
        dependentOneself: null,
        dependentProject: null,
        decisionStyle: null,
        motivation: null,
        taboo: null,
        education: null,
        updateTime: null,
        updateId: null,
        createTime: null,
        createId: null,
        delType: null,
      }
    },
     /**
     * 分页前重置分页参数
     */
    getPageListBefore() {
      this.pageConfig.current = 1
      this.getListPage()
    },
  },
  // 进入马上执行
  mounted() {
    this.getListPage()
    this.$store.commit ('navigationListChange', [
      {name: '干系人', url: '/toOpsStakeholderList', query: {}},
    ])
  },
}
</script>

<style scoped>

</style>

